{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cabd23a6-57b4-45be-847c-8ca3869519d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl\n",
    "from pathlib import Path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d38cf0d5-84cc-4d28-88e3-73e8d87f73f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pl.read_csv(\"stock_trades/202207-湘财.xls\", encoding=\"gb18030\", separator=\"\\t\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "23babd12-fa17-4d48-9383-a6e2bf946866",
   "metadata": {},
   "outputs": [],
   "source": [
    "def read_df_湘财(f: str | Path) -> pl.DataFrame: \n",
    "    df = pl.read_csv(f, encoding=\"gb18030\", separator=\"\\t\", infer_schema=False)\n",
    "    df = df.with_columns(\n",
    "        pl.selectors.all().str.strip_prefix(\"=\").str.strip_chars('\"'),\n",
    "    ).with_columns(\n",
    "        pl.col(\"发生日期\").str.to_date(\"%Y%m%d\"),\n",
    "        # pl.col(\"证券代码\").str.strip_prefix(\"=\").str.strip_chars('\"'), \n",
    "        pl.col(\"成交时间\").str.to_time(), \n",
    "        pl.col(\"成交数量\", \"成交价格\", \"成交金额\", \"发生金额\", \"手续费\", \"印花税\", \"过户费\", \"其他费\").cast(pl.Float64)\n",
    "    )\n",
    "    df = df.filter(\n",
    "        pl.col(\"业务名称\").is_in([\"证券买入\", \"证券卖出\"]), \n",
    "    )\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "402abc5e-8141-47a6-a6d5-d814cb3ab6eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (3, 2)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>foo</th><th>foo2</th></tr><tr><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;asldj1&quot;</td><td>&quot;sldj1&quot;</td></tr><tr><td>&quot;jjjask&quot;</td><td>&quot;jjjask&quot;</td></tr><tr><td>&quot;hasna&quot;</td><td>&quot;hasn&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (3, 2)\n",
       "┌────────┬────────┐\n",
       "│ foo    ┆ foo2   │\n",
       "│ ---    ┆ ---    │\n",
       "│ str    ┆ str    │\n",
       "╞════════╪════════╡\n",
       "│ asldj1 ┆ sldj1  │\n",
       "│ jjjask ┆ jjjask │\n",
       "│ hasna  ┆ hasn   │\n",
       "└────────┴────────┘"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pl.DataFrame(\n",
    "    {\n",
    "        \"foo\": [\"asldj1\", \"jjjask\", \"hasna\"],\n",
    "    }\n",
    ")\n",
    "df.with_columns(foo2=pl.col(\"foo\").str.strip_chars(\"al\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bbce0863-0e92-443f-bbfc-d601189567b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = [read_df_湘财(f) for f in Path(\"stock_trades/\").glob(\"*-湘财.xls\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6b1d69a9-ca4a-4e41-9e8a-b0f94964f311",
   "metadata": {},
   "outputs": [],
   "source": [
    "d1 = pl.concat(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1ec81bde-cc98-45e9-b002-71c88a1d3290",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (257, 17)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>发生日期</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>业务名称</th><th>成交时间</th><th>成交数量</th><th>成交价格</th><th>成交金额</th><th>发生金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>备注</th><th>币种</th><th>券商</th></tr><tr><td>date</td><td>str</td><td>str</td><td>str</td><td>str</td><td>time</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>2022-07-18</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>09:38:10</td><td>-10400.0</td><td>13.2062</td><td>137344.0</td><td>137184.67</td><td>21.98</td><td>137.35</td><td>1.38</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2022-07-18</td><td>&quot;600408&quot;</td><td>&quot;安泰集团&quot;</td><td>&quot;买入&quot;</td><td>&quot;证券买入&quot;</td><td>09:44:52</td><td>47000.0</td><td>3.19</td><td>149930.0</td><td>-149955.5</td><td>23.99</td><td>0.0</td><td>1.51</td><td>0.0</td><td>&quot;证券买入&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2022-07-18</td><td>&quot;600648&quot;</td><td>&quot;外高桥&quot;</td><td>&quot;买入&quot;</td><td>&quot;证券买入&quot;</td><td>09:44:31</td><td>11900.0</td><td>12.6066</td><td>150019.0</td><td>-150044.49</td><td>24.0</td><td>0.0</td><td>1.49</td><td>0.0</td><td>&quot;证券买入&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2022-07-18</td><td>&quot;600269&quot;</td><td>&quot;赣粤高速&quot;</td><td>&quot;买入&quot;</td><td>&quot;证券买入&quot;</td><td>09:43:38</td><td>40700.0</td><td>3.69</td><td>150183.0</td><td>-150208.53</td><td>24.03</td><td>0.0</td><td>1.5</td><td>0.0</td><td>&quot;证券买入&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2022-07-18</td><td>&quot;600015&quot;</td><td>&quot;华夏银行&quot;</td><td>&quot;买入&quot;</td><td>&quot;证券买入&quot;</td><td>09:42:51</td><td>30000.0</td><td>5.07</td><td>152100.0</td><td>-152125.86</td><td>24.34</td><td>0.0</td><td>1.52</td><td>0.0</td><td>&quot;证券买入&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>2023-06-19</td><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>10:18:46</td><td>-5000.0</td><td>9.13</td><td>45650.0</td><td>45596.59</td><td>7.3</td><td>45.65</td><td>0.46</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2023-06-12</td><td>&quot;300641&quot;</td><td>&quot;正丹股份&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>13:22:32</td><td>-9600.0</td><td>5.05</td><td>48480.0</td><td>48423.76</td><td>7.76</td><td>48.48</td><td>0.48</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2023-06-02</td><td>&quot;000655&quot;</td><td>&quot;金岭矿业&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>10:26:35</td><td>-7500.0</td><td>6.48</td><td>48600.0</td><td>48543.61</td><td>7.78</td><td>48.61</td><td>0.47</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2023-06-01</td><td>&quot;300214&quot;</td><td>&quot;日科化学&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>10:45:35</td><td>-7400.0</td><td>6.8</td><td>50320.0</td><td>50261.63</td><td>8.05</td><td>50.32</td><td>0.51</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2023-09-11</td><td>&quot;603577&quot;</td><td>&quot;汇金通&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>09:46:10</td><td>-5100.0</td><td>9.3024</td><td>47442.0</td><td>47410.89</td><td>6.9</td><td>23.72</td><td>0.49</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (257, 17)\n",
       "┌────────────┬──────────┬──────────┬──────────┬───┬────────┬──────────┬────────┬──────┐\n",
       "│ 发生日期   ┆ 证券代码 ┆ 证券名称 ┆ 买卖标志 ┆ … ┆ 其他费 ┆ 备注     ┆ 币种   ┆ 券商 │\n",
       "│ ---        ┆ ---      ┆ ---      ┆ ---      ┆   ┆ ---    ┆ ---      ┆ ---    ┆ ---  │\n",
       "│ date       ┆ str      ┆ str      ┆ str      ┆   ┆ f64    ┆ str      ┆ str    ┆ str  │\n",
       "╞════════════╪══════════╪══════════╪══════════╪═══╪════════╪══════════╪════════╪══════╡\n",
       "│ 2022-07-18 ┆ 002462   ┆ 嘉事堂   ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2022-07-18 ┆ 600408   ┆ 安泰集团 ┆ 买入     ┆ … ┆ 0.0    ┆ 证券买入 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2022-07-18 ┆ 600648   ┆ 外高桥   ┆ 买入     ┆ … ┆ 0.0    ┆ 证券买入 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2022-07-18 ┆ 600269   ┆ 赣粤高速 ┆ 买入     ┆ … ┆ 0.0    ┆ 证券买入 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2022-07-18 ┆ 600015   ┆ 华夏银行 ┆ 买入     ┆ … ┆ 0.0    ┆ 证券买入 ┆ 人民币 ┆ 湘财 │\n",
       "│ …          ┆ …        ┆ …        ┆ …        ┆ … ┆ …      ┆ …        ┆ …      ┆ …    │\n",
       "│ 2023-06-19 ┆ 603967   ┆ 中创物流 ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2023-06-12 ┆ 300641   ┆ 正丹股份 ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2023-06-02 ┆ 000655   ┆ 金岭矿业 ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2023-06-01 ┆ 300214   ┆ 日科化学 ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2023-09-11 ┆ 603577   ┆ 汇金通   ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "└────────────┴──────────┴──────────┴──────────┴───┴────────┴──────────┴────────┴──────┘"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1 = d1.with_columns(\n",
    "    券商=pl.lit(\"湘财\"), \n",
    ")\n",
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0cdd6b24-1d32-48c6-a1f9-5545dad739f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def read_df_海通普通(f: str | Path) -> pl.DataFrame: \n",
    "    df = pl.read_excel(f, schema_overrides={\n",
    "        \"成交日期\": pl.String,\n",
    "        \"成交时间\": pl.String,\n",
    "        \"成交数量\": pl.Float64, \n",
    "        \"成交金额\": pl.Float64, \n",
    "        \"印花税\": pl.Float64, \n",
    "        \"其他费\": pl.Float64, \n",
    "    })\n",
    "    df = df.filter(\n",
    "        pl.col(\"成交时间\")!=\"\"\n",
    "    ).filter(pl.col(\"操作\").is_in([\"买\", \"卖\"])\n",
    "    ).filter(\n",
    "        (~pl.col(\"证券代码\").str.starts_with(\"204\")) \n",
    "        & (~pl.col(\"证券代码\").str.starts_with(\"1318\"))\n",
    "    ).with_columns(\n",
    "        pl.col(\"成交日期\").str.to_date(\"%Y%m%d\"),\n",
    "        pl.col(\"成交时间\").replace({\"\":None}).str.to_time(\"%H:%M:%S\"),\n",
    "    )\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3a1dc5b8-6a39-40bb-a64b-2954945064f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (53, 15)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>证券代码</th><th>证券名称</th><th>成交日期</th><th>成交时间</th><th>成交数量</th><th>成交价格</th><th>成交金额</th><th>发生金额</th><th>操作</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>备注</th><th>券商</th></tr><tr><td>str</td><td>str</td><td>date</td><td>time</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;002224&quot;</td><td>&quot;三 力 士&quot;</td><td>2023-05-23</td><td>09:58:07</td><td>10800.0</td><td>4.59</td><td>49572.0</td><td>-49576.96</td><td>&quot;买&quot;</td><td>4.96</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;三 力 士证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;300107&quot;</td><td>&quot;建新股份&quot;</td><td>2023-05-23</td><td>10:01:57</td><td>10000.0</td><td>5.0</td><td>50000.0</td><td>-50005.0</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;建新股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;603002&quot;</td><td>&quot;宏昌电子&quot;</td><td>2023-05-24</td><td>09:54:48</td><td>9800.0</td><td>5.06</td><td>49588.0</td><td>-49593.46</td><td>&quot;买&quot;</td><td>4.96</td><td>0.0</td><td>0.5</td><td>0.0</td><td>&quot;宏昌电子证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600178&quot;</td><td>&quot;东安动力&quot;</td><td>2023-05-24</td><td>09:59:17</td><td>16400.0</td><td>6.07</td><td>99548.0</td><td>-99558.97</td><td>&quot;买&quot;</td><td>9.95</td><td>0.0</td><td>1.02</td><td>0.0</td><td>&quot;东安动力证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600626&quot;</td><td>&quot;申达股份&quot;</td><td>2023-05-24</td><td>10:06:14</td><td>14800.0</td><td>3.37</td><td>49876.0</td><td>-49881.48</td><td>&quot;买&quot;</td><td>4.99</td><td>0.0</td><td>0.49</td><td>0.0</td><td>&quot;申达股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;603386&quot;</td><td>&quot;骏亚科技&quot;</td><td>2023-07-24</td><td>09:38:22</td><td>4500.0</td><td>11.32</td><td>50940.0</td><td>50883.51</td><td>&quot;卖&quot;</td><td>5.09</td><td>50.91</td><td>0.49</td><td>0.0</td><td>&quot;骏亚科技证券卖出&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;002225&quot;</td><td>&quot;濮耐股份&quot;</td><td>2023-07-24</td><td>09:42:11</td><td>13200.0</td><td>3.8</td><td>50160.0</td><td>-50165.02</td><td>&quot;买&quot;</td><td>5.02</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;濮耐股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600735&quot;</td><td>&quot;新华锦&quot;</td><td>2023-07-24</td><td>09:48:27</td><td>8200.0</td><td>6.07</td><td>49774.0</td><td>-49779.48</td><td>&quot;买&quot;</td><td>4.98</td><td>0.0</td><td>0.5</td><td>0.0</td><td>&quot;新华锦证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;300642&quot;</td><td>&quot;透景生命&quot;</td><td>2023-07-24</td><td>09:49:52</td><td>2500.0</td><td>19.69</td><td>49225.0</td><td>-49229.92</td><td>&quot;买&quot;</td><td>4.92</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;透景生命证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;000823&quot;</td><td>&quot;超声电子&quot;</td><td>2023-07-24</td><td>09:52:23</td><td>5400.0</td><td>9.38</td><td>50652.0</td><td>-50657.07</td><td>&quot;买&quot;</td><td>5.07</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;超声电子证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (53, 15)\n",
       "┌──────────┬──────────┬────────────┬──────────┬───┬────────┬────────┬──────────────────┬──────────┐\n",
       "│ 证券代码 ┆ 证券名称 ┆ 成交日期   ┆ 成交时间 ┆ … ┆ 过户费 ┆ 其他费 ┆ 备注             ┆ 券商     │\n",
       "│ ---      ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---    ┆ ---    ┆ ---              ┆ ---      │\n",
       "│ str      ┆ str      ┆ date       ┆ time     ┆   ┆ f64    ┆ f64    ┆ str              ┆ str      │\n",
       "╞══════════╪══════════╪════════════╪══════════╪═══╪════════╪════════╪══════════════════╪══════════╡\n",
       "│ 002224   ┆ 三 力 士 ┆ 2023-05-23 ┆ 09:58:07 ┆ … ┆ 0.0    ┆ 0.0    ┆ 三 力 士证券买入 ┆ 海通普通 │\n",
       "│ 300107   ┆ 建新股份 ┆ 2023-05-23 ┆ 10:01:57 ┆ … ┆ 0.0    ┆ 0.0    ┆ 建新股份证券买入 ┆ 海通普通 │\n",
       "│ 603002   ┆ 宏昌电子 ┆ 2023-05-24 ┆ 09:54:48 ┆ … ┆ 0.5    ┆ 0.0    ┆ 宏昌电子证券买入 ┆ 海通普通 │\n",
       "│ 600178   ┆ 东安动力 ┆ 2023-05-24 ┆ 09:59:17 ┆ … ┆ 1.02   ┆ 0.0    ┆ 东安动力证券买入 ┆ 海通普通 │\n",
       "│ 600626   ┆ 申达股份 ┆ 2023-05-24 ┆ 10:06:14 ┆ … ┆ 0.49   ┆ 0.0    ┆ 申达股份证券买入 ┆ 海通普通 │\n",
       "│ …        ┆ …        ┆ …          ┆ …        ┆ … ┆ …      ┆ …      ┆ …                ┆ …        │\n",
       "│ 603386   ┆ 骏亚科技 ┆ 2023-07-24 ┆ 09:38:22 ┆ … ┆ 0.49   ┆ 0.0    ┆ 骏亚科技证券卖出 ┆ 海通普通 │\n",
       "│ 002225   ┆ 濮耐股份 ┆ 2023-07-24 ┆ 09:42:11 ┆ … ┆ 0.0    ┆ 0.0    ┆ 濮耐股份证券买入 ┆ 海通普通 │\n",
       "│ 600735   ┆ 新华锦   ┆ 2023-07-24 ┆ 09:48:27 ┆ … ┆ 0.5    ┆ 0.0    ┆ 新华锦证券买入   ┆ 海通普通 │\n",
       "│ 300642   ┆ 透景生命 ┆ 2023-07-24 ┆ 09:49:52 ┆ … ┆ 0.0    ┆ 0.0    ┆ 透景生命证券买入 ┆ 海通普通 │\n",
       "│ 000823   ┆ 超声电子 ┆ 2023-07-24 ┆ 09:52:23 ┆ … ┆ 0.0    ┆ 0.0    ┆ 超声电子证券买入 ┆ 海通普通 │\n",
       "└──────────┴──────────┴────────────┴──────────┴───┴────────┴────────┴──────────────────┴──────────┘"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = [ read_df_海通普通(p) for p in Path(\"stock_trades/\").glob(\"*-海通普通.xlsx\")]\n",
    "df = pl.concat(df)\n",
    "d2 = df.with_columns(\n",
    "    券商=pl.lit(\"海通普通\"), \n",
    ")\n",
    "d2.sort(\"成交日期\", \"成交时间\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2a37e292-442c-4774-a629-f5f128aa7420",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (53, 15)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>证券代码</th><th>证券名称</th><th>成交日期</th><th>成交时间</th><th>成交数量</th><th>成交价格</th><th>成交金额</th><th>发生金额</th><th>操作</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>备注</th><th>券商</th></tr><tr><td>str</td><td>str</td><td>date</td><td>time</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;600638&quot;</td><td>&quot;新黄浦&quot;</td><td>2023-07-26</td><td>09:33:56</td><td>9300.0</td><td>6.526</td><td>60696.0</td><td>60628.01</td><td>&quot;卖&quot;</td><td>6.68</td><td>60.7</td><td>0.61</td><td>0.0</td><td>&quot;新黄浦证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>2023-07-27</td><td>09:30:42</td><td>8700.0</td><td>6.12</td><td>53244.0</td><td>53184.91</td><td>&quot;卖&quot;</td><td>5.86</td><td>53.23</td><td>0.0</td><td>0.0</td><td>&quot;恒基达鑫证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002136&quot;</td><td>&quot;安 纳 达&quot;</td><td>2023-07-27</td><td>09:32:52</td><td>4400.0</td><td>11.881</td><td>52277.0</td><td>52218.97</td><td>&quot;卖&quot;</td><td>5.75</td><td>52.28</td><td>0.0</td><td>0.0</td><td>&quot;安 纳 达证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;600300&quot;</td><td>&quot;维维股份&quot;</td><td>2023-08-04</td><td>09:36:55</td><td>16400.0</td><td>3.27</td><td>53628.0</td><td>53567.91</td><td>&quot;卖&quot;</td><td>5.9</td><td>53.65</td><td>0.54</td><td>0.0</td><td>&quot;维维股份证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;300241&quot;</td><td>&quot;瑞丰光电&quot;</td><td>2023-08-04</td><td>09:39:38</td><td>9700.0</td><td>5.13</td><td>49761.0</td><td>-49766.47</td><td>&quot;买&quot;</td><td>5.47</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;瑞丰光电证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;002956&quot;</td><td>&quot;西麦食品&quot;</td><td>2023-10-31</td><td>09:31:53</td><td>5000.0</td><td>14.13</td><td>70650.0</td><td>70607.91</td><td>&quot;卖&quot;</td><td>6.74</td><td>35.35</td><td>0.0</td><td>0.0</td><td>&quot;西麦食品证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;603214&quot;</td><td>&quot;爱婴室&quot;</td><td>2023-10-31</td><td>09:39:57</td><td>3100.0</td><td>15.84</td><td>49104.0</td><td>-49109.51</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.51</td><td>0.0</td><td>&quot;爱婴室证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;300132&quot;</td><td>&quot;青松股份&quot;</td><td>2023-10-31</td><td>09:40:55</td><td>9600.0</td><td>5.21</td><td>50016.0</td><td>-50021.0</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;青松股份证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>2023-10-31</td><td>09:43:13</td><td>8400.0</td><td>5.91</td><td>49644.0</td><td>-49649.0</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;恒基达鑫证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002111&quot;</td><td>&quot;威海广泰&quot;</td><td>2023-10-31</td><td>09:44:45</td><td>5400.0</td><td>9.24</td><td>49896.0</td><td>-49901.0</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;威海广泰证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (53, 15)\n",
       "┌──────────┬──────────┬────────────┬──────────┬───┬────────┬────────┬──────────────────┬──────────┐\n",
       "│ 证券代码 ┆ 证券名称 ┆ 成交日期   ┆ 成交时间 ┆ … ┆ 过户费 ┆ 其他费 ┆ 备注             ┆ 券商     │\n",
       "│ ---      ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---    ┆ ---    ┆ ---              ┆ ---      │\n",
       "│ str      ┆ str      ┆ date       ┆ time     ┆   ┆ f64    ┆ f64    ┆ str              ┆ str      │\n",
       "╞══════════╪══════════╪════════════╪══════════╪═══╪════════╪════════╪══════════════════╪══════════╡\n",
       "│ 600638   ┆ 新黄浦   ┆ 2023-07-26 ┆ 09:33:56 ┆ … ┆ 0.61   ┆ 0.0    ┆ 新黄浦证券卖出   ┆ 海通两融 │\n",
       "│ 002492   ┆ 恒基达鑫 ┆ 2023-07-27 ┆ 09:30:42 ┆ … ┆ 0.0    ┆ 0.0    ┆ 恒基达鑫证券卖出 ┆ 海通两融 │\n",
       "│ 002136   ┆ 安 纳 达 ┆ 2023-07-27 ┆ 09:32:52 ┆ … ┆ 0.0    ┆ 0.0    ┆ 安 纳 达证券卖出 ┆ 海通两融 │\n",
       "│ 600300   ┆ 维维股份 ┆ 2023-08-04 ┆ 09:36:55 ┆ … ┆ 0.54   ┆ 0.0    ┆ 维维股份证券卖出 ┆ 海通两融 │\n",
       "│ 300241   ┆ 瑞丰光电 ┆ 2023-08-04 ┆ 09:39:38 ┆ … ┆ 0.0    ┆ 0.0    ┆ 瑞丰光电证券买入 ┆ 海通两融 │\n",
       "│ …        ┆ …        ┆ …          ┆ …        ┆ … ┆ …      ┆ …      ┆ …                ┆ …        │\n",
       "│ 002956   ┆ 西麦食品 ┆ 2023-10-31 ┆ 09:31:53 ┆ … ┆ 0.0    ┆ 0.0    ┆ 西麦食品证券卖出 ┆ 海通两融 │\n",
       "│ 603214   ┆ 爱婴室   ┆ 2023-10-31 ┆ 09:39:57 ┆ … ┆ 0.51   ┆ 0.0    ┆ 爱婴室证券买入   ┆ 海通两融 │\n",
       "│ 300132   ┆ 青松股份 ┆ 2023-10-31 ┆ 09:40:55 ┆ … ┆ 0.0    ┆ 0.0    ┆ 青松股份证券买入 ┆ 海通两融 │\n",
       "│ 002492   ┆ 恒基达鑫 ┆ 2023-10-31 ┆ 09:43:13 ┆ … ┆ 0.0    ┆ 0.0    ┆ 恒基达鑫证券买入 ┆ 海通两融 │\n",
       "│ 002111   ┆ 威海广泰 ┆ 2023-10-31 ┆ 09:44:45 ┆ … ┆ 0.0    ┆ 0.0    ┆ 威海广泰证券买入 ┆ 海通两融 │\n",
       "└──────────┴──────────┴────────────┴──────────┴───┴────────┴────────┴──────────────────┴──────────┘"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = [ read_df_海通普通(p) for p in Path(\"stock_trades/\").glob(\"*-海通两融.xlsx\")]\n",
    "df = pl.concat(df)\n",
    "d3 = df.with_columns(\n",
    "    券商=pl.lit(\"海通两融\"), \n",
    ")\n",
    "d3.sort(\"成交日期\", \"成交时间\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "76c7c97f-53b8-4293-94a1-c7f03540c569",
   "metadata": {},
   "outputs": [],
   "source": [
    "d1 = d1.select(\n",
    "    券商=pl.col(\"券商\"), \n",
    "    交易日期=pl.col(\"发生日期\"), \n",
    "    交易时间=pl.col(\"成交时间\"), \n",
    "    证券代码=pl.col(\"证券代码\"), \n",
    "    证券名称=pl.col(\"证券名称\"), \n",
    "    买卖标志=pl.col(\"买卖标志\").replace({\"证券卖出\": \"卖出\", \"证券买入\": \"买入\"}), \n",
    "    成交价格=pl.col(\"成交价格\"), \n",
    "    成交数量=pl.col(\"成交数量\").abs(), \n",
    "    成交金额=pl.col(\"成交金额\"), \n",
    "    手续费=pl.col(\"手续费\"), \n",
    "    印花税=pl.col(\"印花税\"), \n",
    "    过户费=pl.col(\"过户费\"), \n",
    "    其他费=pl.col(\"其他费\"), \n",
    "    发生金额=pl.col(\"发生金额\"), \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "008c349f-b9f5-4172-933f-b18481007f13",
   "metadata": {},
   "outputs": [],
   "source": [
    "d2 = d2.select(\n",
    "    券商=pl.col(\"券商\"), \n",
    "    交易日期=pl.col(\"成交日期\"), \n",
    "    交易时间=pl.col(\"成交时间\"), \n",
    "    证券代码=pl.col(\"证券代码\"), \n",
    "    证券名称=pl.col(\"证券名称\"), \n",
    "    买卖标志=pl.col(\"操作\").replace({\"卖\": \"卖出\", \"买\": \"买入\"}), \n",
    "    成交价格=pl.col(\"成交价格\"), \n",
    "    成交数量=pl.col(\"成交数量\").abs(), \n",
    "    成交金额=pl.col(\"成交金额\"), \n",
    "    手续费=pl.col(\"手续费\"), \n",
    "    印花税=pl.col(\"印花税\"), \n",
    "    过户费=pl.col(\"过户费\"), \n",
    "    其他费=pl.col(\"其他费\"), \n",
    "    发生金额=pl.col(\"发生金额\"), \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "af1cad3a-383d-414d-bd32-8517e9655dcb",
   "metadata": {},
   "outputs": [],
   "source": [
    "d3 = d3.select(\n",
    "    券商=pl.col(\"券商\"), \n",
    "    交易日期=pl.col(\"成交日期\"), \n",
    "    交易时间=pl.col(\"成交时间\"), \n",
    "    证券代码=pl.col(\"证券代码\"), \n",
    "    证券名称=pl.col(\"证券名称\"), \n",
    "    买卖标志=pl.col(\"操作\").replace({\"卖\": \"卖出\", \"买\": \"买入\"}), \n",
    "    成交价格=pl.col(\"成交价格\"), \n",
    "    成交数量=pl.col(\"成交数量\").abs(), \n",
    "    成交金额=pl.col(\"成交金额\"), \n",
    "    手续费=pl.col(\"手续费\"), \n",
    "    印花税=pl.col(\"印花税\"), \n",
    "    过户费=pl.col(\"过户费\"), \n",
    "    其他费=pl.col(\"其他费\"), \n",
    "    发生金额=pl.col(\"发生金额\"), \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "162910e3-76a1-48db-86c2-c28367851f09",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pl.concat([d1, d2, d3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f84bc399-6c15-497b-a649-4e8af9438ec1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (363, 17)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>成交金额2</th><th>成交金额D</th><th>发生金额D</th></tr><tr><td>str</td><td>date</td><td>time</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:44:52</td><td>&quot;600408&quot;</td><td>&quot;安泰集团&quot;</td><td>&quot;买入&quot;</td><td>3.19</td><td>47000.0</td><td>149930.0</td><td>23.99</td><td>0.0</td><td>1.51</td><td>0.0</td><td>-149955.5</td><td>149930.0</td><td>0.0</td><td>0.0</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:44:31</td><td>&quot;600648&quot;</td><td>&quot;外高桥&quot;</td><td>&quot;买入&quot;</td><td>12.6066</td><td>11900.0</td><td>150019.0</td><td>24.0</td><td>0.0</td><td>1.49</td><td>0.0</td><td>-150044.49</td><td>150018.54</td><td>0.46</td><td>0.0</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:43:38</td><td>&quot;600269&quot;</td><td>&quot;赣粤高速&quot;</td><td>&quot;买入&quot;</td><td>3.69</td><td>40700.0</td><td>150183.0</td><td>24.03</td><td>0.0</td><td>1.5</td><td>0.0</td><td>-150208.53</td><td>150183.0</td><td>0.0</td><td>0.0</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:42:51</td><td>&quot;600015&quot;</td><td>&quot;华夏银行&quot;</td><td>&quot;买入&quot;</td><td>5.07</td><td>30000.0</td><td>152100.0</td><td>24.34</td><td>0.0</td><td>1.52</td><td>0.0</td><td>-152125.86</td><td>152100.0</td><td>0.0</td><td>0.0</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:39:28</td><td>&quot;601992&quot;</td><td>&quot;金隅集团&quot;</td><td>&quot;卖出&quot;</td><td>2.5683</td><td>54000.0</td><td>138686.0</td><td>22.19</td><td>138.69</td><td>1.38</td><td>0.0</td><td>138523.74</td><td>138688.2</td><td>-2.2</td><td>0.0</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-10-24</td><td>09:37:27</td><td>&quot;300283&quot;</td><td>&quot;温州宏丰&quot;</td><td>&quot;买入&quot;</td><td>5.4038</td><td>12900.0</td><td>69709.0</td><td>11.15</td><td>0.0</td><td>0.83</td><td>0.0</td><td>-69720.15</td><td>69709.02</td><td>-0.02</td><td>0.83</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-10-11</td><td>09:32:03</td><td>&quot;000900&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;卖出&quot;</td><td>3.8465</td><td>34400.0</td><td>132321.0</td><td>21.17</td><td>132.35</td><td>1.31</td><td>0.0</td><td>132167.48</td><td>132319.6</td><td>1.4</td><td>1.31</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:38:10</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;卖出&quot;</td><td>13.2062</td><td>10400.0</td><td>137344.0</td><td>21.98</td><td>137.35</td><td>1.38</td><td>0.0</td><td>137184.67</td><td>137344.48</td><td>-0.48</td><td>1.38</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>09:33:37</td><td>&quot;000900&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;买入&quot;</td><td>4.05</td><td>34400.0</td><td>139320.0</td><td>22.29</td><td>0.0</td><td>1.39</td><td>0.0</td><td>-139342.29</td><td>139320.0</td><td>0.0</td><td>1.39</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>09:38:16</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;买入&quot;</td><td>13.51</td><td>10400.0</td><td>140504.0</td><td>22.48</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-140526.48</td><td>140504.0</td><td>0.0</td><td>1.41</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (363, 17)\n",
       "┌──────┬────────────┬──────────┬──────────┬───┬────────────┬───────────┬───────────┬───────────┐\n",
       "│ 券商 ┆ 交易日期   ┆ 交易时间 ┆ 证券代码 ┆ … ┆ 发生金额   ┆ 成交金额2 ┆ 成交金额D ┆ 发生金额D │\n",
       "│ ---  ┆ ---        ┆ ---      ┆ ---      ┆   ┆ ---        ┆ ---       ┆ ---       ┆ ---       │\n",
       "│ str  ┆ date       ┆ time     ┆ str      ┆   ┆ f64        ┆ f64       ┆ f64       ┆ f64       │\n",
       "╞══════╪════════════╪══════════╪══════════╪═══╪════════════╪═══════════╪═══════════╪═══════════╡\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:44:52 ┆ 600408   ┆ … ┆ -149955.5  ┆ 149930.0  ┆ 0.0       ┆ 0.0       │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:44:31 ┆ 600648   ┆ … ┆ -150044.49 ┆ 150018.54 ┆ 0.46      ┆ 0.0       │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:43:38 ┆ 600269   ┆ … ┆ -150208.53 ┆ 150183.0  ┆ 0.0       ┆ 0.0       │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:42:51 ┆ 600015   ┆ … ┆ -152125.86 ┆ 152100.0  ┆ 0.0       ┆ 0.0       │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:39:28 ┆ 601992   ┆ … ┆ 138523.74  ┆ 138688.2  ┆ -2.2      ┆ 0.0       │\n",
       "│ …    ┆ …          ┆ …        ┆ …        ┆ … ┆ …          ┆ …         ┆ …         ┆ …         │\n",
       "│ 湘财 ┆ 2022-10-24 ┆ 09:37:27 ┆ 300283   ┆ … ┆ -69720.15  ┆ 69709.02  ┆ -0.02     ┆ 0.83      │\n",
       "│ 湘财 ┆ 2022-10-11 ┆ 09:32:03 ┆ 000900   ┆ … ┆ 132167.48  ┆ 132319.6  ┆ 1.4       ┆ 1.31      │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:38:10 ┆ 002462   ┆ … ┆ 137184.67  ┆ 137344.48 ┆ -0.48     ┆ 1.38      │\n",
       "│ 湘财 ┆ 2022-07-11 ┆ 09:33:37 ┆ 000900   ┆ … ┆ -139342.29 ┆ 139320.0  ┆ 0.0       ┆ 1.39      │\n",
       "│ 湘财 ┆ 2022-07-11 ┆ 09:38:16 ┆ 002462   ┆ … ┆ -140526.48 ┆ 140504.0  ┆ 0.0       ┆ 1.41      │\n",
       "└──────┴────────────┴──────────┴──────────┴───┴────────────┴───────────┴───────────┴───────────┘"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.with_columns(\n",
    "    成交金额2=pl.col(\"成交价格\") * pl.col(\"成交数量\"),\n",
    ").with_columns(\n",
    "    成交金额D=pl.col(\"成交金额\") - pl.col(\"成交金额2\"), \n",
    ").with_columns(\n",
    "    发生金额D=(\n",
    "        pl.col(\"发生金额\") \n",
    "        - (\n",
    "        pl.when(pl.col(\"买卖标志\") == \"买入\")\n",
    "        .then(-pl.col(\"成交金额\"))\n",
    "        .when(pl.col(\"买卖标志\") == \"卖出\")\n",
    "        .then(pl.col(\"成交金额\"))\n",
    "        - pl.col(\"手续费\")\n",
    "        - pl.col(\"印花税\")\n",
    "        - pl.col(\"过户费\")\n",
    "        - pl.col(\"其他费\")\n",
    "        )\n",
    "    ).round(4)\n",
    ").sort(\"发生金额D\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "c2afe6ac-56c9-408d-b43c-8bb651258131",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.write_parquet(\"stock_trades.parquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "9e28bc9a-e38f-486d-9772-6ee4006cda27",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.write_csv(\"stock_trades.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "d69ad005-c4fc-4764-a347-b5f15699a264",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<xlsxwriter.workbook.Workbook at 0x1fbd8e200e0>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.write_excel(\"stock_trades.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d8d3121-4d8b-451e-9689-7ba69c17adbb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
